﻿using ImageDefine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ImageTool2DCal
{
    [Serializable]
    public class ImageTool2DCal : ImageToolBase,IPoint,ILineTool
    {
        public ToolSetting Setting;
        public string strFormName;
        public string strToName;
        public double dResultRow1, dResultCol1, dResultRow2, dResultCol2;
        [NonSerialized]
        public ImageActioner2DCal actioner;
        public ImageTool2DCal() : base()
        {
            Setting = new ToolSetting();
            strFormName = "";
            strToName = "";
        }
        public ImageTool2DCal(ImageToolBase imageBase) : base(imageBase)
        {
            Setting = new ToolSetting();
            strFormName = "";
            strToName = "";
        }
        override public void CreateActioner(ImageTask imageTaskIn)
        {
            imageTask = imageTaskIn;
            OutPutResults = new Dictionary<string, string>();
            strTaskName = imageTask.Name;
            actioner = new ImageActioner2DCal(this);
        }
        override public void Run(HalconDotNet.HImage hImage, SmartDisplayControl.SmartDisplayControl smartDisplay)
        {
            actioner.Run(hImage, smartDisplay);
        }

        public static ImageToolTypeInfo ToolTypeRegister()
        {
            ImageToolTypeInfo imageToolTypeInfo = new ImageToolTypeInfo();
            imageToolTypeInfo.ToolName = "计算工具";
            imageToolTypeInfo.toolType = typeof(ImageTool2DCal);
            return imageToolTypeInfo;
        }
        public override Form ShowSettingFrm()
        {
            FormSetting formSetting = new FormSetting(imageTask, this, actioner);
            return formSetting;
        }

        public bool GetLine(out double dRow1, out double dCol1, out double dRow2, out double dCol2)
        {
            dRow1 = this.dResultRow1;
            dCol1 = this.dResultCol1;
            dRow2 = this.dResultRow2;
            dCol2 = this.dResultCol2;
            return bResultOK;
        }

        public bool GetPoint(out double dResultX, out double dResultY)
        {
            dResultX = this.ResultX;
            dResultY = this.ResultY;
            return bResultOK;
        }

        public bool GetPoint(out double dResultX, out double dResultY, int iIndex)
        {
            dResultX = this.ImageToolResults[iIndex].ResultX;
            dResultY = this.ImageToolResults[iIndex].ResultY;
            return bResultOK;
        }

        public bool GetLine(out double dRow1, out double dCol1, out double dRow2, out double dCol2, int iIndex)
        {
            ImageResultLine imageToolResultLine = ImageToolResults[iIndex] as ImageResultLine;
            dCol1 = imageToolResultLine.LineStartX;
            dRow1 = imageToolResultLine.LineStartY;
            dCol2 = imageToolResultLine.LineEndX;
            dRow2 = imageToolResultLine.LineEndY;

            return imageToolResultLine.Result; ;
        }
    }
}
